package com.lagou.beans;

import net.bytebuddy.asm.Advice;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedissonBean {

    @Bean(name = "stringRedisTemplate")
    public StringRedisTemplate getStringRedisTemplate() {

        JedisConnectionFactory factory = new JedisConnectionFactory();
        factory.setHostName("192.168.80.121");
        factory.setPort(6379);

        StringRedisTemplate template = new StringRedisTemplate();
        template.setConnectionFactory(factory);

        return template;
    }

    @Bean(name = "redisson")
    public Redisson getRedisson() {

        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.80.121:6379").setDatabase(0);

        return (Redisson) Redisson.create(config);
    }
}
